﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VoL.Domain.Common.DTO;
using VoL.Domain.Infrastructure;
using VoL.Domain.IServices.IPatientFile;
using VOL.Entity.DomainModels;

namespace VoL.Domain.Services.PatientFile
{
    /// <summary>
    /// 患者服务实现类
    /// </summary>
    public partial class PatientService : IPatientsService
    {
        /// <summary>
        /// 患者仓储
        /// </summary>
        private readonly IBaseRepository<Patient> _baseRepository;
        /// <summary>
        /// 入院评估仓储
        /// </summary>
        private readonly IBaseRepository<InAssess> _inAssessRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="baseRepository">患者仓储</param>
        /// <param name="inAssessRepository">入院评估仓储</param>
        public PatientService(IBaseRepository<Patient> baseRepository, IBaseRepository<InAssess> inAssessRepository)
        {
            _baseRepository = baseRepository;
            _inAssessRepository = inAssessRepository;
        }

        /// <summary>
        /// 查询病房患者
        /// </summary>
        /// <returns>返回查询到的数据</returns>
        public List<Patient> Getpatients()
        {
            var info = _baseRepository.GetAll();
            //List<PatientDTO> dtos = new List<PatientDTO>();
            //foreach (var item in info)
            //{
            //    PatientDTO dto = new PatientDTO()
            //    {
            //        Id = item.Id,
            //        Name = item.Name,
            //        NursingUnit = item.NursingUnit,
            //    };
            //    dtos.Add(dto);
            //}dtos
            return info.ToList();
        }


        /// <summary>
        /// 添加/修改患者入院评估
        /// </summary>
        /// <param name="patient">数据</param>
        /// <returns>返回结果</returns>
        public async Task<int> CreatePatientInAssess(InAssess inAssess)
        {
            int i = 0;
            if (inAssess.Id == 0)
            {
                i = await _inAssessRepository.Add(inAssess);
            }
            else
            {
                i = await _inAssessRepository.Update(inAssess);
            }
            return i;
        }
    }
}
